package com.ly.oa.service.flow.impl;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ly.core.service.impl.BaseServiceImpl;
import com.ly.core.util.DateUtil;
import com.ly.oa.dao.flow.FormDataDao;
import com.ly.oa.model.flow.FormData;
import com.ly.oa.service.flow.FormDataService;

public class FormDataServiceImpl extends BaseServiceImpl<FormData> implements FormDataService{
	private FormDataDao dao;
	
	public FormDataServiceImpl(FormDataDao dao) {
		super(dao);
		this.dao=dao;
	}
	/*
	 * (non-Javadoc)
	 * @see com.ly.oa.service.flow.FormDataService#getFromDataMap(java.lang.Long, java.lang.String)
	 */
	public Map getFromDataMap(Long runId,String activityName){
		List<FormData> list=dao.getByRunIdActivityName(runId, activityName);
		Map dataMap=new HashMap();
		String v;
		for(FormData form:list){
			if("datetime".equals(form.getFieldType()))
				dataMap.put(form.getFieldName(),DateUtil.formatDate((Timestamp)form.getValue(),"yyyy-MM-dd"));
			else
				dataMap.put(form.getFieldName(),form.getValue());
		}
		return dataMap;
	}
	@Override
	public List getByFormId(Long formId) {
		return dao.getByFormId(formId);
	}
}